package org.jeecg.modules.fund.controller;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.fund.entity.FundLibrary;
import org.jeecg.modules.fund.entity.FundValue;
import org.jeecg.modules.fund.mapper.FundValueMapper;
import org.jeecg.modules.fund.model.FundValLineModel;
import org.jeecg.modules.fund.service.IFundValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "基金净值")
@RequestMapping("/sys/fund/value")
@Slf4j
public class FundValueController {
    @Autowired
    private FundValueMapper fundValueMapper;
    @Autowired
    private IFundValueService fundValueService;

    @RequestMapping(value = "/data", method = RequestMethod.GET)
    public Result<String> data() {
        fundValueService.batchUpdateThsValue();
        return Result.ok();
    }

    /**
     * 净值分页
     * @param fundValue
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public Result<IPage<Map<String, Object>>> queryPageList(FundValue fundValue,
                                                            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                            @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize,
                                                            HttpServletRequest req) {
        // 分页设置
        Page<FundValue> page = new Page<>(pageNo, pageSize);
        // 分页
        String code = fundValue.getFundId().substring(5);
        IPage<Map<String, Object>> pageList = fundValueMapper.selectPageVo(fundValueService.tableName(code),page,fundValue);
        return Result.OK(pageList);
    }
}
